package com.zang.blogz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zang.blogz.annotation.OptLog;
import com.zang.blogz.constant.OptTypeConstant;
import com.zang.blogz.entity.OperationLog;
import com.zang.blogz.model.output.admin.AdminOperationLogVO;
import com.zang.blogz.result.Result;
import com.zang.blogz.service.OperationLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 朵橙i
 * @since 2022-06-17
 */
@RestController
@Api(tags = "日志模块")
@RequestMapping("/blogz/operationLog")
public class OperationLogController {

    @Autowired
    private OperationLogService operationLogService;

    @GetMapping("/admin/list")
    @ApiOperation(value = "获取日志列表", notes = "获取日志列表")
    public Result<IPage<AdminOperationLogVO>> pageResult(@RequestParam(value = "moduleName", required = false) String moduleName,
                                                         @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                         @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize){

        Page<OperationLog> page = new Page<>(pageNo,pageSize);

        return Result.ok(operationLogService.pageResult(moduleName, page));
    }

    @DeleteMapping("/admin/delete")
    @ApiOperation(value = "根据日志id删除日志", notes = "根据日志id删除日志")
    @OptLog(optType = OptTypeConstant.REMOVE)
    public Result<String> deleteById(@RequestParam(value = "logId") Integer logId){

        return operationLogService.deleteByLogId(logId);
    }

}
